SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_AddSearchItem]
   @Title       NVARCHAR(200),
   @Description NVARCHAR(2000),
   @Author      INT,
   @PubDate     DATETIME,
   @ModuleId    INT,
   @SearchKey   NVARCHAR(100),
   @Guid        NVARCHAR(200),
   @ImageFileId INT
AS
  DECLARE  @ID INT
  SELECT @ID = SearchItemId
  FROM   dbo.DnnProduct_SearchItem
  WHERE  ModuleId = @ModuleID
         AND SearchKey = @SearchKey
  IF @ID IS NULL
    BEGIN
      INSERT INTO dbo.DnnProduct_SearchItem
                 ([Title],
                  [Description],
                  [Author],
                  [PubDate],
                  [ModuleId],
                  [SearchKey],
                  [guId],
                  [HitCount],
                  [ImageFileId])
      VALUES     (@Title,
                  @Description,
                  @Author,
                  @PubDate,
                  @ModuleId,
                  @SearchKey,
                  @Guid,
                  0,
                  @ImageFileId)
      SELECT Scope_identity()
    END
  ELSE
    BEGIN
      UPDATE dbo.DnnProduct_SearchItem
      SET    [Title] = @Title,
             [Description] = @Description,
             [Author] = @Author,
             [PubDate] = @PubDate,
             [ModuleId] = @ModuleId,
             [SearchKey] = @SearchKey,
             [guId] = @Guid,
             [HitCount] = [HitCount] + 1,
             [ImageFileId] = @ImageFileId
      WHERE  SearchItemId = @ID
      SELECT @ID
    END
GO
